package org.kyw.quartz.job;

import org.kyw.order.service.IAdoptOrderService;
import org.kyw.quartz.constant.JobTypeConstants;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;

public class MainJob implements Job {
    @Autowired
    private IAdoptOrderService adoptOrderService;

    @Override
    public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
        JobDataMap jobDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        Map<String,Object> map = (Map<String, Object>) jobDataMap.get("params");
        String type = (String) map.get("type");
        switch (type) {
            case JobTypeConstants.TIME_OUT_ADOPT_LAST_PAY:{
                Long orderId = (Long) map.get("orderId");
                adoptOrderService.cancelByQuartz(orderId);
                break;
            }
            default:break;
        }
    }
}
